
export function logoutSystem(permiss, router) {
    permiss.setRouteState(false);
    sessionStorage.clear();
    let routers = router.getRoutes();
    routers.map((it: any) => {
        if (!["/login", "/403", "/"].includes(it.path)) {
            console.log("it.path", it.path);
            router.removeRoute(it.name);
        }
    });
    router.push("/login");
}
export function GetDateStr(AddDayCount) {
    //AddDayCount ,传入的日期
    var dd = new Date();
    dd.setDate(dd.getDate() + AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1);//获取当前月份的日期，不足10补0
    var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();//获取当前几号，不足10补0
    return y + "-" + m + "-" + d
}
export function getDateStuff() {
    return {
        start: " 00:00:00",
        end: " 23:59:59"
    }
}
//0:问题分类 1：考题分类 2.问题分类和考题分类
export function getCategoryTypes() {
    return [{
        label: '问题分类',
        value: 0
    }, {
        label: '考题分类',
        value: 1
    }, {
        label: '问题分类和考题分类',
        value: 2
    }]
}
export function getObj(array: Array<any>, id: number | string) {
    return array.find(t => t.value === id)
}
// 验证是否为blob格式
export function blobValidate(data) {
    return data.type !== 'application/json'
}

export function treeToArray(tree) {
    const result: Object[] = [];

    function helper(node, parentId) {
        if (node.id === parentId) return;

        const item: any = { ...node, children: [] };
        delete item.children;
        result.push(item);

        if (node.children) {
            for (let child of node.children) {
                helper(child, node.id);
            }
        }
    }

    for (let node of tree) {
        helper(node, null);
    }

    return result;
}